package com.competition.reception.controller;


import com.competition.commonutils.JwtUtils;
import com.competition.commonutils.R;
import com.competition.reception.entity.CourseVideo;
import com.competition.reception.entity.vo.VideoQueryVo;
import com.competition.reception.service.CourseVideoService;
import com.competition.reception.service.ManageService;
import com.competition.servicebase.exceptionhandler.MyException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-04-04
 */
@RestController
@RequestMapping("/reception/course-video")
@CrossOrigin
@Api( description = "后台视频上传相关的接口")
public class CourseVideoController {

    @Autowired
    private CourseVideoService courseVideoService;

    @PostMapping("addCourse")
    @ApiOperation("添加课程的接口")
    public R uploadVideo(@RequestBody CourseVideo video, HttpServletRequest request) {
        String manageId = JwtUtils.getMemberIdByJwtToken(request);
        video.setManagerId(manageId);
        System.out.println(video);
        boolean save = courseVideoService.save(video);
        if(save){
            return R.ok();
        }else {
            return R.error().data("msg","视频添加失败");
        }
    }

    @ApiOperation("讲堂的高级查询加分页")
    @PostMapping("getVideoList")
    public R getVideo(@RequestBody VideoQueryVo queryVo) {
        R video = courseVideoService.getVideoList(queryVo);
        return video;
    }

    @ApiOperation("删除讲堂，根据讲堂id")
    @DeleteMapping("deleteVideo/{id}")
    public R deleteVideo(@PathVariable("id") String id) {
        boolean flag = courseVideoService.removeById(id);
        return flag == true ? R.ok() : R.error();
    }


}

